package com.cake.liulanxiangzhu.controller;

import com.cake.liulanxiangzhu.pojo.dto.CakeProductDTO;
import com.cake.liulanxiangzhu.pojo.dto.CakeProductInsertDTO;
import com.cake.liulanxiangzhu.pojo.vo.CakeProductVO;
import com.cake.liulanxiangzhu.service.ICakeProductService;
import com.cake.liulanxiangzhu.web.JsonPage;
import com.cake.liulanxiangzhu.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cakeProduct")
public class CakeProductController {
    @Autowired
    private ICakeProductService service;

    @PostMapping("/addCake")
    public JsonResult<Void> addCake(CakeProductInsertDTO cakeProductInsertDTO) {
        System.out.println("cakeProductInsertDTO = " + cakeProductInsertDTO);
        service.addCake(cakeProductInsertDTO);
        return JsonResult.ok();
    }

    /**
     * <span> 02001显示所有甜品信息
     *
     * @param page
     * @param pageSize
     * @return JsonPage<CakeProductVO>
     * @author dinghao
     * @date 2023/1/7 13:32
     */
    @GetMapping("/queryCakes")
    public JsonResult<JsonPage<CakeProductVO>> queryCakes(Integer page, Integer pageSize) {
        JsonPage<CakeProductVO> cakeProductVOJsonPage = service.allCakes(page, pageSize);
        return JsonResult.ok(cakeProductVOJsonPage);
    }

    @GetMapping("/queryAllCake")
    public JsonResult<List<CakeProductVO>> queryAllCake() {
        List<CakeProductVO> vos = service.listSpu();
        return JsonResult.ok(vos);

    }

    /**
     * <span>02003删除甜品信息
     *
     * @param cakeId
     * @return void
     * @author dinghao
     * @date 2023/1/7 13:33
     */
    @PostMapping("/deleteCake")
    public JsonResult<Void> deleteCake(Integer cakeId) {
        service.deleteCake(cakeId);
        return JsonResult.ok();
    }

    /**
     * <span> 02004修改甜品信息
     *
     * @param cakeProductDTO
     * @return
     * @author dinghao
     * @date 2023/1/7 17:26
     */
    @PostMapping("/updateCake")
    public JsonResult<Void> updateCake(CakeProductDTO cakeProductDTO, Integer cakeId) {
        service.updateCake(cakeProductDTO, cakeId);
        return JsonResult.ok();
    }

    /**
     * <span> 02005下架商品
     *
     * @param cakeId
     * @return void
     * @author dinghao
     * @date 2023/1/7 17:48
     */
    @PostMapping("/downPublished")
    public JsonResult<Void> downPublished(Integer cakeId) {
        service.updateDownPublished(cakeId);
        return JsonResult.ok();
    }

    /**
     * <span> 02006上架商品
     *
     * @param cakeId
     * @return void
     * @author dinghao
     * @date 2023/1/7 18:30
     */
    @PostMapping("/sendPublished")
    public JsonResult<Void> sendPublished(Integer cakeId) {
        service.updateSendPublished(cakeId);
        return JsonResult.ok();
    }

    /**
     * <span> 根据ID查询甜品信息
     *
     * @param cakeId
     * @return JsonResult<CakeProductVO>
     * @author dinghao
     * @date 2023/1/8 22:20
     */
    @GetMapping("/queryCake")
    public JsonResult<CakeProductVO> queryCake(Integer cakeId) {
        CakeProductVO vo = service.queryCake(cakeId);
        return JsonResult.ok(vo);
    }

    @GetMapping("/queryCakeWx")
    public JsonResult<List<CakeProductVO>> queryCakeWx(Integer categoryId) {
        List<CakeProductVO> productVOS = service.queryPms(categoryId);
        return JsonResult.ok(productVOS);
    }



    @GetMapping("/queryBySales")
    public JsonResult<List<CakeProductVO>> querySales() {
        List<CakeProductVO> vos = service.querySale();
        return JsonResult.ok(vos);
    }



}
